<template>
  <div class="app-container">
    <el-card shadow="never" v-loading="loading">
      <el-row :gutter="5">
        <el-col :span="24" class="main-card-view">
          <el-row>
            <el-card shadow="never" class="top-search-view-card">
              <el-row>
                <el-form :inline="true" :model="searchForm" class="demo-form-inline search-view">
                  <el-form-item>
                    <el-button type="primary" @click="add" class="search-button">添加</el-button>
                  </el-form-item>
                </el-form>
              </el-row>
            </el-card>
          </el-row>

          <el-row>
            <el-card shadow="never">
              <el-table :data="tableData" :stripe="true" style="width: 100%">

                <el-table-column prop="approvalFlowName" align="center" label="审批流程名称" />
               <!-- <el-table-column prop="classify" align="center" label="审批内容">
                  <template slot-scope="{row}">
                    <div v-for="(item, i) in row.approvalContents" :key="i">{{ item }}</div>
                  </template>
                </el-table-column> -->
                <el-table-column prop="approvalLevel" align="center" label="审批层级" />
                <el-table-column prop="publisherNum" align="center" label="专家数量">
                  <template slot-scope="{row}">
                    <el-button @click="goPublisher(row)" type="text">{{ row.publisherNum }}</el-button>
                  </template>
                </el-table-column>
                <el-table-column prop="approvalProNum" align="center" label="审批人数量">
                  <template slot-scope="{row}">
                    <el-button @click="goApprovalPro(row)" type="text">{{ row.approvalProNum }}</el-button>
                  </template>
                </el-table-column>
                <el-table-column prop="userName" align="center" label="操作">
                  <template slot-scope="{row}">
                    <el-button @click="edit(row)" type="text" class="table-edit-btn"></el-button>
                    <el-button @click="handleDelete(row)" type="text" class="table-delete-btn"></el-button>
                  </template>
                </el-table-column>
              </el-table>
              <XPagination ref="pageInfo" :total="total" :get-data="getList" />
            </el-card>
          </el-row>
        </el-col>
      </el-row>
    </el-card>

  </div>
</template>

<script>
import XPagination from "../../components/xpagination/XPagination";
import * as ApprovalConfig from "../../api/expertApprovalConfig"
export default {
  name: "list",
  components: { XPagination },
  data () {
    return {
      searchForm: {
        titleName: ""
      },
      tableData: [],
      loading: false,
      dialogVisible: false,
      total: 0,
    }
  },
  methods: {
    getList (pageInfo) {
      const param = {
        ...this.searchForm,
        ...pageInfo
      }
      ApprovalConfig.queryByPage(param).then(response => {
        console.log(response)
        this.tableData = response.data.data.rows
        this.total = response.data.data.total
        this.loading = false
      }).catch(error => {
        console.log(error)
      })
    },
    handleSearch () {
      this.$refs.pageInfo.loadData()
    },
    add () {
      this.$router.push({
        path: '/expertManagement/expertApprovalFlow',
        query: {
          status: 'add'
        }
      })
    },
    edit (data) {
      delete data.createTime
      delete data.updateTime
      sessionStorage.setItem('ApprovalConfig', JSON.stringify(data))
      this.$router.push({
        path: '/expertManagement/expertApprovalFlow',
        query: {
          status: 'edit'
        }
      })
    },
    handleDelete (data) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const param = {
          uid: data.uid,
        }
        this.loading = true
        ApprovalConfig.deleteById(param).then(result => {
          this.loading = false
          this.$message.success(result.data.msg)
          this.handleSearch()
        }).catch(error => {
          this.loading = false
          console.log(error)
        })
      }).catch(() => {
        console.log('取消删除')
      });
    },
    goPublisher (data) {
      this.$router.push({
        path: 'expertPublisher',
        query: { uid: data.uid }
      })
    },
    goApprovalPro (data) {
      this.$router.push({
        path: 'expertApprovalPro',

        query: { uid: data.uid, lv: data.approvalLevel }
      })
    }
  },
  mounted () {
    this.handleSearch()
  }
}
</script>

<style scoped lang="scss"></style>
